<template>
  <div :style="computedStyle" class="text-box" @mouseover="onMouseOver($event)" @mouseout="onMouseOut($event)">
    {{ text }}
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  text: String,
  top: Number,
  left: Number,
  scale: Number,
  opacity: Number,
  backgroundImage: String, // 新增背景图片属性
});

const computedStyle = computed(() => ({
  top: `${props.top}px`,
  left: `${props.left}px`,
  transform: `scale(${props.scale})`,
  opacity: props.opacity,
  backgroundImage: `url(${props.backgroundImage})`, // 动态设置背景图片
  backgroundSize: 'cover', // 设置背景图片的大小
  backgroundPosition: 'center', // 居中显示背景图片
}));

function onMouseOver(event) {
  event.currentTarget.style.transform = 'translate(-50%, -50%) scale(1.5)';
}

function onMouseOut(event) {
  event.currentTarget.style.transform = 'translate(-50%, -50%) scale(1)';
}
</script>

<style scoped>
.text-box {
  position: absolute;
  color: #FFA500;
  background-color: rgba(228, 170, 10, 0.7);
  /* 背景透明度 */
  padding: 15px 25px;
  /* 调整内边距 */
  border-radius: 5px;
  transition: all 0.3s ease;
  font-size: 24px;
  /* 字体大小 */
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
  /* 阴影效果 */
  background-blend-mode: multiply;
  /* 混合背景图片与颜色 */
}

.text-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 165, 0, 0.5);
  /* 蒙层颜色（半透明黄色） */
  z-index: -1;
  /* 放置在图形的下层 */
  transition: background-color 0.3s ease;
  /* 添加平滑过渡效果 */
}

.text-box:hover {
  border-color: gray;
  /* 鼠标移入时边框颜色变为灰色 */
}

.text-box:hover::before {
  background-color: rgba(128, 128, 128, 0.3);
  /* 鼠标移入时蒙层颜色变为灰色 */
}
</style>
